package com.situ.web.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.situ.web.dao.IBanJiCourseDao;
import com.situ.web.util.JDBCUtil;
import com.situ.web.util.ModelConvertUtil;

public class BanJiCourseDaoImpl implements IBanJiCourseDao {

	@Override
	public List<Map<String, Object>> findAllInformation() {
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		Connection connection = null;
		List<Map<String, Object>> list = null;
		try {
			connection = JDBCUtil.getConnection();
			String sql = "SELECT b.id as 'b_id',b.`name` as 'b_name',"
					+ "c.`name` as 'c_name',c.credit as 'c_credit' FROM banji as b "
					+ "INNER JOIN banji_course as bc ON b.id=bc.banji_id INNER JOIN "
					+ "course as c ON bc.course_id=c.id;";
			preparedStatement = connection.prepareStatement(sql);
			resultSet = preparedStatement.executeQuery();
			list = ModelConvertUtil.converToList(resultSet);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

}
